package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.VO.VOCompanyJob;
import com.chixing.entity.Job;
import com.chixing.mapper.JobMapper;
import com.chixing.service.IJobService;
import com.chixing.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author smith
 * @since 2025-09-17
 */
@Service
public class JobServiceImpl implements IJobService {

    @Autowired
    private JobMapper jobMapper;
    @Override
    public Result getById(Integer id) {
        Job job = jobMapper.selectById(id);
        if (job!=null)
            return Result.getSuccess(job);
        return Result.getFail(job);
    }

///jobTitle/java/jobSalaryMin/15000.00/jobSalaryMax/25000.00/experienceRequired/3-5/jobLocation/北京/educationRequired/Bachelor/employmentType/Full-time
    @Override
    public Result getByConditions(String jobTitle, Double jobSalaryMin, Double jobSalaryMax, String experienceRequired, String jobLocation, String educationRequired, String employmentType) {
        QueryWrapper<Job> wrapper = new QueryWrapper<>();
        //根据职位名称，薪资范围，工作年限，所在城市，学历，是否全职 查询所有有效的Job
        wrapper.like("job_title","%"+jobTitle +"%")
                .ge("job_salary_min",jobSalaryMin)
                .le("job_salary_max",jobSalaryMax)
                .eq("experience_required",experienceRequired)
                .eq("job_location",jobLocation)
                .eq("education_required",educationRequired)
                .eq("employment_type",employmentType);
        List<Job> jobs = jobMapper.selectList(wrapper);
        if (jobs!=null && jobs.size()>0)
            return Result.getSuccess(jobs);
        return Result.getFail(jobs);
    }

    //http://localhost:8080/app/job/searchAll
    @Override
    public Result getAll() {
        List<Job> jobs = jobMapper.selectList(null);
        if (jobs!=null&&jobs.size()>0)
            return Result.getSuccess(jobs);
        return Result.getFail(jobs);
    }

    @Override
    public Result getComJob() {
        List<VOCompanyJob> jobs = jobMapper.selectAllJob();
        if (jobs!=null&&jobs.size()>0)
            return Result.getSuccess(jobs);
        return Result.getFail(jobs);
    }

    @Override
    public Result getConditions(String jobName, Float minJobSalary, Float maxJobSalary, String workYear, String jobCity, String degree, String employeeType) {
        List<VOCompanyJob> voCompanyJobs = jobMapper.selectConditions(jobName, minJobSalary, maxJobSalary, workYear, jobCity, degree, employeeType);
        if (voCompanyJobs!=null && voCompanyJobs.size()>0)
            return Result.getSuccess(voCompanyJobs);
        return Result.getFail(voCompanyJobs);
    }


}
